package com.ruoyi.web.controller.record;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.record.domain.WordStudyStepProgress;
import com.ruoyi.record.service.IWordStudyStepProgressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单词学习进程Controller
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@RestController
@RequestMapping("/record/step_progress")
public class WordStudyStepProgressController extends BaseController
{
    @Autowired
    private IWordStudyStepProgressService wordStudyStepProgressService;

    /**
     * 查询单词学习进程列表
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:list')")
    @GetMapping("/list")
    public TableDataInfo list(WordStudyStepProgress wordStudyStepProgress)
    {
        startPage();
        Long userId = getUserId();
        wordStudyStepProgress.setStudentId(userId);
        List<WordStudyStepProgress> list = wordStudyStepProgressService.selectWordStudyStepProgressList(wordStudyStepProgress);
        return getDataTable(list);
    }

    @GetMapping("/listAll")
    public TableDataInfo listAll(WordStudyStepProgress wordStudyStepProgress)
    {
        startPage();
        List<WordStudyStepProgress> list = wordStudyStepProgressService.selectWordStudyStepProgressList(wordStudyStepProgress);
        return getDataTable(list);
    }

    @GetMapping("/user")
    public TableDataInfo list_user(WordStudyStepProgress wordStudyStepProgress)
    {
        startPage();
        String username = getUsername();
        wordStudyStepProgress.setPeople(username);
        List<WordStudyStepProgress> list = wordStudyStepProgressService.selectWordStudyStepProgressList(wordStudyStepProgress);
        return getDataTable(list);
    }

    /**
     * 导出单词学习进程列表
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:export')")
    @Log(title = "单词学习进程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WordStudyStepProgress wordStudyStepProgress)
    {
        List<WordStudyStepProgress> list = wordStudyStepProgressService.selectWordStudyStepProgressList(wordStudyStepProgress);
        ExcelUtil<WordStudyStepProgress> util = new ExcelUtil<WordStudyStepProgress>(WordStudyStepProgress.class);
        util.exportExcel(response, list, "单词学习进程数据");
    }

    /**
     * 获取单词学习进程详细信息
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(wordStudyStepProgressService.selectWordStudyStepProgressById(id));
    }

    /**
     * 新增单词学习进程
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:add')")
    @Log(title = "单词学习进程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WordStudyStepProgress wordStudyStepProgress)
    {
        return toAjax(wordStudyStepProgressService.insertWordStudyStepProgress(wordStudyStepProgress));
    }

    /**
     * 修改单词学习进程
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:edit')")
    @Log(title = "单词学习进程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WordStudyStepProgress wordStudyStepProgress)
    {
        return toAjax(wordStudyStepProgressService.updateWordStudyStepProgress(wordStudyStepProgress));
    }

    /**
     * 删除单词学习进程
     */
//    @PreAuthorize("@ss.hasPermi('record:step_progress:remove')")
    @Log(title = "单词学习进程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wordStudyStepProgressService.deleteWordStudyStepProgressByIds(ids));
    }
}
